// $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.alwaysOverridetoString.alwaysOverrideToString
/* Copyright (c) 2011 Team A CS2340. All rights reserved.*/

package edu.gatech.teama.doctorsoffice.test;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import edu.gatech.teama.doctorsoffice.client.view.MainWindow;
import edu.gatech.teama.doctorsoffice.server.Server;

/**
 * Run the server in a background thread and the client as well
 * @author Team A
 * @version $Revision: 1.0 $
 *
 */
public class RunServerAndClient {

	public static void startServer() { // $codepro.audit.disable methodJavadoc
		final Server srv;
        final Socket clientSocket;
        final ObjectOutputStream out;
        final ObjectInputStream in; // $codepro.audit.disable variableUsage
        final ExecutorService pool;
        final String testDataFileName = "test.dat";
        
        try {
                // Execute server on new thread
                srv = new Server(4123, testDataFileName); // $codepro.audit.disable numericLiterals
                pool = Executors.newSingleThreadExecutor();
                pool.execute(srv);

                // Give the server some time to start
                Thread.sleep(100); // $codepro.audit.disable numericLiterals

                clientSocket = new Socket("localhost", 4123); // $codepro.audit.disable closeWhereCreated, numericLiterals

                out = new ObjectOutputStream(clientSocket.getOutputStream()); // $codepro.audit.disable closeWhereCreated
                out.flush();
                in = new ObjectInputStream(clientSocket.getInputStream()); // $codepro.audit.disable closeWhereCreated
        } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        }
}
	
	public static void main(String[] args) throws InterruptedException { // $codepro.audit.disable methodJavadoc
		startServer();
		Thread.sleep(1000); // $codepro.audit.disable numericLiterals
		MainWindow.main(null);
	}
}
